package com.dhj.streamTest2;

import com.dhj.streamTest.entity.Author;

import java.util.List;
import java.util.stream.Stream;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo10 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();

        Stream<Author> streamAu = authors.stream().distinct();

        streamAu.map(author -> author.getName())
                .forEach(name -> System.out.println(name));

        System.out.println("---------------------------------");

        /**
         * streamAu已经关闭，不能再次操作，需要重新定义。
         * Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed
         */
        streamAu.map(author -> author.getName())
                .forEach(name -> System.out.println(name));

    }
}
